package org.skatiger.jrove.component.html;

import org.skatiger.jrove.renderer.Html;
import org.skatiger.jrove.util.AssertUtil;
import org.skatiger.jrove.util.StringUtils;

public class NavigationItem extends HtmlComponentBase {
    public static final String DEFAULT_ITEM_ELEMENT = Html.LI_ELEM;
    public static final String DEFAULT_ACTIVE_CLASSES = "active";

    private String alias;
    private String activeClass;

    public String getAlias() {
        return getPropertyValue("alias", alias, DEFAULT_ITEM_ELEMENT);
    }

    public void setAlias(String alias) {
        this.alias = alias;
    }

    public String getActiveClass() {
        String _activeClass = getPropertyValue("activeClass", activeClass,
                DEFAULT_ACTIVE_CLASSES);
        if (StringUtils.isNotBlank(_activeClass)) {
            return _activeClass;
        }
        return getNavigation().getActiveClass();
    }

    public void setActiveClass(String activeClass) {
        this.activeClass = activeClass;
    }

    @Override
    public String getStyleClass() {
        StringBuilder buf = new StringBuilder();
        if (isActive()) {
            buf.append(getActiveClass()).append(" ");
        }
        String _styleClass = super.getStyleClass();
        if (StringUtils.isNotBlank(_styleClass)) {
            buf.append(_styleClass);
        }
        return buf.toString();
    }

    protected Navigation getNavigation() {
        Navigation parent = (Navigation) findParentComponent(Navigation.class);
        AssertUtil.notNull(parent);
        return parent;
    }

    private boolean isActive() {
        return getNavigation().isActive(getId());
    }

}
